<template>
  <div class="search">
    <Card>
      <div style="text-align: center">
        <div style="width: 500px; display: inline-block; text-align: left">
          <Form
            :model="formValue"
            label-position="left"
            label-colon
            :label-width="100"
            :rules="rules"
            ref="form"
          >
            <!-- <FormItem label="退款订单号">
              <Input v-model="formValue.outTradeNo" />
            </FormItem>
            <FormItem label="">
              <Checkbox v-model="formValue.isCombine">是否合单</Checkbox>
            </FormItem> -->
            <FormItem label="操作类型">
              <RadioGroup v-model="formValue.actionType">
                <Radio label="1">添加</Radio>
                <Radio label="2">删除</Radio>
              </RadioGroup>
            </FormItem>
            <FormItem label="接收方类型">
              <RadioGroup v-model="formValue.type">
                <Radio label="MERCHANT_ID">商户</Radio>
                <Radio label="PERSONAL_OPENID">个人</Radio>
              </RadioGroup>
            </FormItem>
            <FormItem label="接收方账号" prop="account">
              <Input v-model="formValue.account" />
            </FormItem>
            <template v-if="formValue.actionType == 1">
              <FormItem
                label="接收方名称"
                v-if="formValue.type == 'MERCHANT_ID'"
                prop="name"
              >
                <Input v-model="formValue.name" />
              </FormItem>
              <FormItem label="关系类型">
                <RadioGroup v-model="formValue.relation_type">
                  <Radio label="SUPPLIER">供应商</Radio>
                  <Radio label="DISTRIBUTOR">分销商</Radio>
                  <Radio label="SERVICE_PROVIDER">服务商</Radio>
                  <Radio label="PLATFORM">平台</Radio>
                  <Radio label="OTHERS">其他</Radio>
                </RadioGroup>
              </FormItem>
            </template>
            <FormItem label="">
              <Button type="primary" @click="handleOk">确定</Button>
            </FormItem>
          </Form>
        </div>
      </div>
    </Card>
  </div>
</template>

<script>
import * as API_Order from "@/api/order";

export default {
  name: "fastReturnMoneyOrder",
  data() {
    return {
      loading: true, // 表单加载状态
      formValue: {
        actionType: "1",
        type: "PERSONAL_OPENID",
        relation_type: "DISTRIBUTOR",
      },
      rules: {
        account: [{ required: true, message: "请输入账号" }],
        name: [{ required: true, message: "请输入名称" }],
      },
    };
  },
  methods: {
    handleOk() {
      this.$refs.form.validate(async (valid) => {
        if (valid) {
          const res = await API_Order.profitSharing({ ...this.formValue });
          if (res.success) {
            this.$Message.success("操作成功");
          } else {
            this.$Message.success(res.message);
          }
        }
      });
    },
  },
  mounted() {},
  // 页面缓存处理，从该页面离开时，修改KeepAlive为false，保证进入该页面是刷新
  beforeRouteLeave(to, from, next) {
    from.meta.keepAlive = false;
    next();
  },
};
</script>
<style lang="scss">
// 建议引入通用样式 可删除下面样式代码
@import "@/styles/table-common.scss";
</style>
